package org.activequant.math.simulation;

import java.util.Iterator;
/**
 * AR1Generator implements Iterator&lt;Double&gt;<br/>
 * Holds the following associated variables:
 * <ul>
 * <li>mean(double)</li>
 * <li>value(double)</li>
 * <li>phi(double)</li>
 * <li>noise(Iterator&lt;Double&gt;)</li>
 * </ul>
 * @author Dimitar
 *
 */
public class AR1Generator implements Iterator<Double> {
	/**
	 * private double mean = 0.0;
	 */
	private double mean = 0.0;
	/**
	 * private double value = 0.0;
	 */
	private double value = 0.0;
	/**
	 * private double phi = 0.5;
	 */
	private double phi = 0.5;
	/**
	 * private Iterator&lt;Double&gt; noise = new GaussianRandomGenerator();
	 */
	private Iterator<Double> noise = new GaussianRandomGenerator();
	/**
	 * sets the associated mean(double) with the given val(double)
	 * @param val
	 */
	public void setMean(double val) {
		mean = val;
	}
	/**
	 * returns the associated mean(double)
	 * @return
	 */
	public double getMean() {
		return mean;
	}
	/**
	 * sets the associated value(double) with the given val(double)
	 * @param val
	 */
	public void setValue(double val) {
		value = val;
	}
	/**
	 * returns the associated value(double)
	 * @return
	 */
	public double getValue() {
		return value;
	}
	/**
	 * sets the associated phi(double) with the given val(double)
	 * @param val
	 */
	public void setPhi(double val) {
		phi = val;
	}
	/**
	 * returns the associated phi(double)
	 * @return
	 */
	public double getPhi() {
		return phi;
	}
	
	/**
	 * sets the associated noise(Iterator&lt;Double&gt;) with the given valI(Iterator&lt;Double&gt;)
	 * @param val
	 */
	public void setNoise(Iterator<Double> val) {
		noise = val;
	}
	/**
	 * returns true
	 */
	public boolean hasNext() {
		return true;
	}
	/**
	 * sets and returns the associated value(double) as:<br/>
	 * <code>${mean} + ${phi}*(${value} - ${mean}) + ${noise.next}</code>
	 */
	public Double next() {
		value = mean + phi * (value - mean) + noise.next();
		return value;
	}
	/**
	 * throws an UnsupportedOperationException
	 */
	public void remove() {
		throw new UnsupportedOperationException();
	}
}
